package com.cp.www.ws;

import org.kurento.client.IceCandidate;
import org.kurento.client.MediaPipeline;
import org.kurento.client.PlayerEndpoint;
import org.kurento.client.WebRtcEndpoint;
import org.springframework.web.socket.WebSocketSession;

public class UserSession {

	private int delay;// 播放延迟 ms
	private boolean close;// 是否标注为关闭
	private String rtspUrl;
	private boolean presenter;// 是否是第一个播放器
	private WebRtcEndpoint webRtcEndpoint;
	private MediaPipeline mediaPipeline;
	private PlayerEndpoint playerEndpoint;
	private WebSocketSession webSocketSession;

	public WebRtcEndpoint getWebRtcEndpoint() {
		return webRtcEndpoint;
	}

	public UserSession setWebRtcEndpoint(WebRtcEndpoint webRtcEndpoint) {
		this.webRtcEndpoint = webRtcEndpoint;
		return this;
	}

	public MediaPipeline getMediaPipeline() {
		return mediaPipeline;
	}

	public UserSession setMediaPipeline(MediaPipeline mediaPipeline) {
		this.mediaPipeline = mediaPipeline;
		return this;
	}

	public UserSession addCandidate(IceCandidate candidate) {
		webRtcEndpoint.addIceCandidate(candidate);
		return this;
	}

	public PlayerEndpoint getPlayerEndpoint() {
		return playerEndpoint;
	}

	public UserSession setPlayerEndpoint(PlayerEndpoint playerEndpoint) {
		this.playerEndpoint = playerEndpoint;
		return this;
	}

	public int getDelay() {
		return delay;
	}

	public UserSession setDelay(int delay) {
		this.delay = delay;
		return this;
	}

	public String getRtspUrl() {
		return rtspUrl;
	}

	public UserSession setRtspUrl(String rtspUrl) {
		this.rtspUrl = rtspUrl;
		return this;
	}

	public boolean isPresenter() {
		return presenter;
	}

	public UserSession setPresenter(boolean presenter) {
		this.presenter = presenter;
		return this;
	}

	public boolean isClose() {
		return close;
	}

	public UserSession setClose(boolean close) {
		this.close = close;
		return this;
	}

	public WebSocketSession getWebSocketSession() {
		return webSocketSession;
	}

	public UserSession setWebSocketSession(WebSocketSession webSocketSession) {
		this.webSocketSession = webSocketSession;
		return this;
	}

	public void release() {
		this.playerEndpoint.stop();
		this.mediaPipeline.release();
	}

}
